home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / libraries / mui20dev.lha / MUI / Developer / C / Examples / Settings.c < prev    next >
C/C++ Source or Header  |  1994-02-11  |  4KB  |  156 lines

  1. /*
  2. ** The Settings Demo shows how to load and save object contents.
  3. */
  4.  
  5. #include "demo.h"
  6.  
  7. #define ID_CANCEL 1
  8. #define ID_SAVE   2
  9. #define ID_USE    3
  10.  
  11. int main(int argc,char *argv[])
  12. {
  13.     APTR app,window,str1,str2,str3,str4,sl1,cy1,btsave,btuse,btcancel;
  14.     ULONG signals;
  15.     BOOL running = TRUE;
  16.     char *sex[] = { "male", "female", NULL };
  17.  
  18.     init();
  19.  
  20.     app = ApplicationObject,
  21.         MUIA_Application_Title      , "Settings",
  22.         MUIA_Application_Version    , "$VER: Settings 7.37 (10.02.94)",
  23.         MUIA_Application_Copyright  , "©1992/93, Stefan Stuntz",
  24.         MUIA_Application_Author     , "Stefan Stuntz",
  25.         MUIA_Application_Description, "Show saving and loading of settings",
  26.         MUIA_Application_Base       , "SETTINGS",
  27.  
  28.         SubWindow, window = WindowObject,
  29.             MUIA_Window_Title, "Save/use me and start me again!",
  30.             MUIA_Window_ID   , MAKE_ID('S','E','T','T'),
  31.  
  32.             WindowContents, VGroup,
  33.  
  34.                 Child, ColGroup(2), GroupFrameT("User Identification"),
  35.                     Child, Label2("Name:"),
  36.                     Child, str1 = StringObject, StringFrame, MUIA_ExportID, 1, End,
  37.                     Child, Label2("Street:"),
  38.                     Child, str2 = StringObject, StringFrame, MUIA_ExportID, 2, End,
  39.                     Child, Label2("City:"),
  40.                     Child, str3 = StringObject, StringFrame, MUIA_ExportID, 3, End,
  41.                     Child, Label1("Password:"),
  42.                     Child, str4 = StringObject, StringFrame, MUIA_ExportID, 4, MUIA_String_Secret, TRUE, End,
  43.                     Child, Label1("Sex:"),
  44.                     Child, cy1  = CycleObject, MUIA_Cycle_Entries, sex, MUIA_ExportID, 6, End,
  45.                     Child, Label("Age:"),
  46.                     Child, sl1  = SliderObject, MUIA_ExportID, 5, MUIA_Slider_Min, 9, MUIA_Slider_Max, 99, End,
  47.                     End,
  48.  
  49.                 Child, VSpace(2),
  50.  
  51.                 Child, HGroup, MUIA_Group_SameSize, TRUE,
  52.                     Child, btsave   = KeyButton("Save",'s'),
  53.                     Child, HSpace(0),
  54.                     Child, btuse    = KeyButton("Use",'u'),
  55.                     Child, HSpace(0),
  56.                     Child, btcancel = KeyButton("Cancel",'>'),
  57.                     End,
  58.  
  59.                 End,
  60.             End,
  61.         End;
  62.  
  63.     if (!app)
  64.         fail(app,"Failed to create Application.");
  65.  
  66.  
  67. /*
  68. ** Install notification events...
  69. */
  70.  
  71.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  72.         app,2,MUIM_Application_ReturnID,ID_CANCEL);
  73.  
  74.     DoMethod(btcancel,MUIM_Notify,MUIA_Pressed,FALSE,
  75.         app,2,MUIM_Application_ReturnID,ID_CANCEL);
  76.  
  77.     DoMethod(btsave,MUIM_Notify,MUIA_Pressed,FALSE,
  78.         app,2,MUIM_Application_ReturnID,ID_SAVE);
  79.  
  80.     DoMethod(btuse,MUIM_Notify,MUIA_Pressed,FALSE,
  81.         app,2,MUIM_Application_ReturnID,ID_USE);
  82.  
  83.  
  84. /*
  85. ** Cycle chain for keyboard control
  86. */
  87.  
  88.     DoMethod(window,MUIM_Window_SetCycleChain,
  89.         str1,str2,str3,str4,cy1,sl1,btsave,btuse,btcancel,NULL);
  90.  
  91.  
  92. /*
  93. ** Concatenate strings, <return> will activate the next one
  94. */
  95.  
  96.     DoMethod(str1,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  97.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str2);
  98.  
  99.     DoMethod(str2,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  100.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str3);
  101.  
  102.     DoMethod(str3,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  103.         window,3,MUIM_Set,MUIA_Window_ActiveObject,str4);
  104.  
  105.     DoMethod(str4,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,
  106.         window,3,MUIM_Set,MUIA_Window_ActiveObject,btuse);
  107.  
  108.  
  109. /*
  110. ** The application is set up, now load
  111. ** a previously saved configuration from env:
  112. */
  113.  
  114.     DoMethod(app,MUIM_Application_Load,MUIV_Application_Load_ENV);
  115.  
  116.  
  117.  
  118. /*
  119. ** Input loop...
  120. */
  121.  
  122.     set(window,MUIA_Window_Open,TRUE);
  123.     set(window,MUIA_Window_ActiveObject,str1);
  124.  
  125.     while (running)
  126.     {
  127.         switch (DoMethod(app,MUIM_Application_Input,&signals))
  128.         {
  129.             case MUIV_Application_ReturnID_Quit:
  130.             case ID_CANCEL:
  131.                 running = FALSE;
  132.                 break;
  133.  
  134.             case ID_SAVE:
  135.                 DoMethod(app,MUIM_Application_Save,MUIV_Application_Save_ENVARC);
  136.                 /* fall through */
  137.  
  138.             case ID_USE:
  139.                 DoMethod(app,MUIM_Application_Save,MUIV_Application_Save_ENV);
  140.                 running = FALSE;
  141.                 break;
  142.         }
  143.  
  144.         if (running && signals) Wait(signals);
  145.     }
  146.  
  147.     set(window,MUIA_Window_Open,FALSE);
  148.  
  149.  
  150. /*
  151. ** Shut down...
  152. */
  153.  
  154.     fail(app,NULL);
  155. }
  156.